#include <reg52.h>
#include <intrins.h>
#include <stdlib.h>
#include <delay.h>
#define LCD_data P0
sbit LCD_RS=P1^5;
sbit LCD_RW=P1^6;
sbit LCD_EN=P1^7;

//RS=L,RW=L;E=???,P0-P7=???
void write_cmd(uchar cmd)
{
	LCD_RS=0;
	LCD_RW=0;
	LCD_EN=0;
	P0=cmd;
	delay_ms(5);
	LCD_EN=1;
	delay_ms(5);
	LCD_EN=0;
}

//RS=H,RW=L,E=???,D0-D7=??
void write_dat(uchar dat)
{
	LCD_RS=1;
	LCD_RW=0;
	LCD_EN=0;
	P0=dat;
	delay_ms(5);
	LCD_EN=1;
	delay_ms(5);
	LCD_EN=0;
}

void lcd_pos(uchar X,uchar Y)
{
	uchar pos;
	if (X==0)
		X=0x80;
	else if (X==1)
		X=0x90;
	else if (X==2)
		X=0x88;
	else if (X==3)
		X=0x98;
	pos=X+Y;
	write_cmd(pos);
}

void lcd_init()
{
	//LCD_PSB=1;
	write_cmd(0x30);
	delay_ms(5);
	write_cmd(0x0c);
	delay_ms(5);
	write_cmd(0x01);
	delay_ms(5);
}

void lcd_string(uchar x,uchar y,uchar *s)
{
	uchar i;
	EA=0;
	lcd_pos(x,y);
	for (i=0;i<16;i++)
	{
		write_dat(s[i]);
	}
	EA=1;
}
